# -*- coding: utf-8 -*-

from osv import fields,osv
from osv.orm import browse_record
import tools
from functools import partial
import pytz
import pooler
from tools.translate import _
from service import security
import netsvc

general_state = (
    ('draft', 'Draft'),
    ('confirmed', 'Confirmed'),
    ('approved', 'Approved'),
)

class aas_academic_year(osv.osv):
    _name = 'aas.academic.year'
    _description = 'Academic Year'
    _columns = {
        'name': fields.char('Academic Year', size=64, required=True),
        'code': fields.char('Code', size=64),
        'date_start': fields.date('Date Start'),
        'date_end': fields.date('Date End'),
        'academic_semesters': fields.one2many('aas.academic.semester', 'academic_year', string='Semesters'),
    }
aas_academic_year()

class aas_academic_semester(osv.osv):
    _name = 'aas.academic.semester'
    _description = 'Academic Semester'
    _columns = {
        'name': fields.char('Semester', size=64, required=True),
        'academic_year': fields.many2one('aas.academic.year', string='Academic Year', required=True),
        'date_start': fields.date('Date Start'),
        'date_end': fields.date('Date End'),
        'academic_weeks': fields.one2many('aas.academic.week', 'academic_semester', string='Academic Weeks'),
    }
aas_academic_semester()

class aas_academic_week(osv.osv):
    _name = 'aas.academic.week'
    _description = 'Academic Week'
    _columns = {
        'name': fields.char('Academic Week Number', size=64, required=True),
        'academic_semester': fields.many2one('aas.academic.semester', string='Semester', required=True),
        'date_start': fields.date('Date Start'),
        'date_end': fields.date('Date End'),
    }
aas_academic_week()

class aas_current_academic_state(osv.osv):
    _name = 'aas.current.academic.state'
    _description = 'Current Academic State'
    _columns = {
        'academic_year': fields.many2one('aas.academic.year', string='Academic Year', required=True),
        'academic_semester': fields.many2one('aas.academic.semester', string='Semester', required=True),
        'academic_week': fields.many2one('aas.academic.week', string='Academic Week', required=True),
    }
aas_current_academic_state()

class aas_academic_degree(osv.osv):
    _name = 'aas.academic.degree'
    _description= 'Academic Degree'
    _columns = {
        'name': fields.char('Academic Degree', size=64, required=True),
    }
aas_academic_degree()

class aas_academic_type(osv.osv):
    _name = 'aas.academic.type'
    _description= 'Academic Type'
    _columns = {
        'name': fields.char('Academic Type', size=64, required=True),
    }
aas_academic_type()

class aas_academic_session(osv.osv):
    _name = 'aas.academic.session'
    _description= 'Academic Session'
    _columns = {
        'name': fields.char('Academic Session', size=64, required=True),
        'academic_degree': fields.many2one('aas.academic.degree', string='Academic Degree', required=True),
        'academic_type': fields.many2one('aas.academic.type', string='Academic Type', required=True),
        'date_start': fields.date('Date Start'),
        'date_end': fields.date('Date End'),
    }
aas_academic_session()

class aas_academic_plan(osv.osv):
    _name = 'aas.academic.plan'
    _description= 'Academic Plan'
    _columns = {
        'name': fields.char('Academic Plan', size=128, required=True),
        'comment1': fields.text('Comment From Creator'),
        'comment2': fields.text('Comment From Validator'),
        'creator': fields.many2one('res.users', string='Creator', readonly=True),
        'validator': fields.many2one('res.users', string='Validator', readonly=True),
        'academic_year': fields.many2one('aas.academic.year', string='Academic Year', required=True),
        'state': fields.selection(general_state, string='State', readonly=True),
        'academic_plan_line': fields.one2many('aas.academic.plan.line', 'academic_plan', 'Academic Plan Line'),
    }
    _defaults = {
        'state': lambda *a: 'draft',
        'creator': lambda self, cr, uid, context: uid,
    }
    
    def confirm(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': 'confirmed', 'validator': False})
        return True
    
    def approve(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': 'approved', 'validator': uid})
        return True
    
    def refuse(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': 'draft', 'validator': False})
        return True
    
    def set_back_to_draft(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': 'draft', 'validator': False})
        return True
    
aas_academic_plan()

class aas_academic_week_state(osv.osv):
    _name = 'aas.academic.week.state'
    _description= 'Academic Week State'
    _columns = {
        'name': fields.char('Academic Week State Name', size=128, required=True),
        'code': fields.char('Academic Week State Code', size=128, required=True),
    }
aas_academic_week_state()

class aas_academic_plan_line(osv.osv):
    _name = 'aas.academic.plan.line'
    _description= 'Academic Plan Line'
    _columns = {
        'academic_plan': fields.many2one('aas.academic.plan', string='Academic Plan', required=True),
        'academic_session': fields.many2one('aas.academic.session', string='Academic Session', required=True),
        'academic_week': fields.many2one('aas.academic.week', string='Academic Week', required=True),
        'academic_week_state': fields.many2one('aas.academic.week.state', string='Academic Week State', required=True),
    }
aas_academic_plan_line()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
